<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri= "http://java.sun.com/jsp/jstl/fmt" prefix= "fmt" %>
<%@ include file="/inc/css.inc"%>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>大讲堂</title>
		<link rel="stylesheet" href="${css}/amazeui.css" />
		<link rel="stylesheet" href="${css}/classplay.css" />
		<link rel="stylesheet" href="${css}/dropload.css" />
		<script src="${js}/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="${js}/dropload.js"></script>
	</head>
	<script type="text/javascript">
		$(function(){
			var cookieVal = localStorage.patientid;  //获取 local storage 
			if( typeof (cookieVal)  ==  "undefined" || cookieVal ==  undefined){
				window.location.href = "<%=basePath%>web/enrollment/joyin/letter.jsp?a=slectSyllabusList";
			}
		});
	</script>
	<body>
		<div class="box">
			<div class="header">
				课程回顾
				<%-- <span><a href="${syllabus.coursewareUrl}">课件<a/></span> --%>
			</div>
			<div class="content">
				<article class="am-comment">
					<a href=""><img class="am-comment-avatar" src="${img}/userimg.png" alt=""/></a>
					<audio src="${syllabus.tapeUrl}" style="display:none" id="mp3" autoplay preload controls ></audio>
<!-- 					<button onclick="times()">运算</button>
					<button onclick="times2()">当前时间</button> -->
					<input id="servertime" type="hidden" value="${syllabus.auditoriumStartTime}" />
					<input id="syllabusId" type="hidden" value="${syllabus.id}">
				  <div class="am-comment-main reddotbox">
				  	<span class="reddot"></span>
				    <header class="am-comment-hd">
				      <!--<h3 class="am-comment-title">评论标题</h3>-->
				      <div class="am-comment-meta">				       
				 		<img width="20px" src="${img}/wifi.gif" />
				      </div>
				    </header> 
				  </div>
				</article>
			</div>
			<div class="footer">
				<div class="footer-left">
					<input id="chatmsg" type="text" class="" placeholder="请输入您的问题" />
				</div>
				<div class="footer-right">
					<img class="publishbtn" height="36px" src="${img}/publish.png" onclick="publishmsg()"/>
					<img class="msgbtn" height="36px" src="${img}/message.png" />
				</div>
			</div>
		</div>
		<!--评论区展示-->
		<div class="msgbox">
			<div class="msgcont">
				<a class="am-close am-close-alt closebtn">&times;</a>
				<div id="msglistbox" class="msglistbox">
					<ul class="am-comments-list pinglun mui-table-view mui-table-view-chevron">
						<div class="lists"></div>
					</ul>
				</div>			
			</div>
		</div>
		<script>
		//获取留言
		getinter()
	//音频控制
	function audioplay(id){
	    var audio = document.getElementById('mp3');
	   audio.paused?audio.pause():audio.play();
	    document.addEventListener("WeixinJSBridgeReady", function () {
	          !audio.paused?audio.pause():audio.play();
	    }, false); 
	}
	
	$(function(){
		audioplay('mp3');
		//setTimeout('gotime()',1000)
		setInterval('addUserHeartbea', 180000);
	});
	
	function addUserHeartbea(){
		var syllabusId = 1;
		var patientId = 1;
		$.ajax({
			type:"post",
	   		url:"<%=basePath%>addUserHeartbea.action",
	   		async:false,
	   		data:{syllabusId: syllabusId, patientId: patientId},
	   		success:function(){
	   		}
		});
	}

	//音频控制结束	
			
		  	
		  	function getinter(){
			    var counter = 0;
			    // 每页展示4个
			    var num = 10;
			    var pageStart = 0,pageEnd = 0;
				var userType = 0;
				var syllabusId = $("#syllabusId").val();
			    // dropload
			    $('.pinglun').dropload({
			        scrollArea : window,
			        loadDownFn : function(me){
			            $.ajax({
			                type: 'POST',
			                url: '<%=basePath%>interflowAllSyllabus.action',
			                dataType: 'json',
			                data:{syllabusId: syllabusId, userType: userType},
			                success: function(data){
			                	if(data.content.length==0){
			                		$(".msglistbox").html('<div style="text-align:center;padding-top:20px;">暂无评论</div>');
			                		$(".dropload-load").css('display','none')
			                	}else{
			                		var result = '';
				                    counter++;
				                    pageEnd = num * counter;
				                    pageStart = pageEnd - num;
				                    for(var i = pageStart; i < pageEnd; i++){
				                        result +=   '<li class="am-comment border-b-no"><a href="#link-to-user-home"><img src="${img}/bbsbanner.png" alt="" class="am-comment-avatar" width="48" height="48"/></a> <div class="am-comment-main"><header class="am-comment-hd"><div class="am-comment-meta"><a href="#link-to-user" class="am-comment-author">'+data.content[i].nickName+'</a></div></header><div class="am-comment-bd border-b ptcont">'+data.content[i].message+' </div></div></li>';
				                        if((i + 1) >= data.content.length){
				                            // 锁定
				                            me.lock();
				                            // 无数据
				                            me.noData();
				                            break;
				                        }
				                    }
				                    // 为了测试，延迟1秒加载
				                    setTimeout(function(){
				                        $('.lists').append(result);
				                        // 每次数据加载完，必须重置
				                        me.resetload();
				                    },1000);
			                	}
			                    
			                },
			                error: function(xhr, type){
			                    //alert('Ajax error!');
			                    // 即使加载出错，也得重置
			                    me.resetload();
			                }
			            });
			        }
			    });
			};
		  	
		  	//按钮事件		  	

		  	//留言展示
		  	$(".msgbtn").click(function(){
		  		$(".msgbox").fadeIn(300);
		  	});
		  	
		  	//发送留言
		  	function publishmsg(){
		  		var message = $("#chatmsg").val();
		  		var id = localStorage.patientid;
		  		var syllabusId = $("#syllabusId").val();
		  		var userType = 0;
		  		//alert(message);
		  		if(message!=''){
		  			$.ajax({
		  				type:"post",
				   		url:"<%=basePath%>addInterflow.action",
				   		async:false,
				   		data:{userId: id, message: message, syllabusId: syllabusId, userType: userType},
				   		success:function(v){
				   			$(".lists").html('');
				   			getinter()
				   		}
		  			});
		  		}
		  	} 
		  	
		  	//关闭展示
		  	$(".closebtn").click(function(){
		  		$(".msgbox").fadeOut(300);
		  	})
		</script>
	</body>
</html>
